home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / oop.swg / 0024_Passing method as OBJect.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  920b  |  50 lines

  1. {
  2. Stuart Maclean
  3.  
  4. Hi there, I've found a neat way of passing an Object a method of its own
  5. class, which it then executes. The idea comes from Smalltalk's
  6. change/update mechanism For dependencies under the MVC paradigm.
  7.  
  8. Works under TP6.
  9. }
  10.  
  11. Type
  12.   DependentPtr = ^Dependent;
  13.  
  14.   Dependent = Object
  15.                 Procedure Update(p : Pointer);
  16.                 Procedure SomeMethod;
  17.               end;
  18.  
  19.   Model = Object
  20.             dep : DependentPtr;
  21.             Procedure Change;
  22.           end;
  23.  
  24. Procedure Dependent.Update; Assembler;
  25. Asm
  26.   les di, self
  27.   push es
  28.   push di
  29.   call dWord ptr p
  30. end;
  31.  
  32. Procedure Dependent.SomeMethod;
  33. begin
  34. { do something here }
  35. end;
  36.  
  37. Procedure Model.Change;
  38. begin
  39.   dep^.Update(@Dependent.Somemethod);
  40. end;
  41.  
  42. Var
  43.   m : Model;
  44.   d : Dependent;
  45.  
  46. begin
  47.   m.dep := @d; { add d as a dependent of m }
  48.   m.Change;  { caUses d to be updated }
  49. end.
  50.